<template>
	<container
		class="address"
		:isNoData="isNoData"
		@btnClick="goToEdit(null)"
		:nodata-option="{
			type: 'hasbtn',
			icon: '/static/dizhi.png',
			iconW:268,
			iconH:300,
			iconBottom: '80rpx',
			text: '您还没有收货地址',
			btnText: '新增收货地址',
		
		}"
	>
		<view class="address-list">
			<address-item
				class="item"
				v-for="(item, index) in addressList"
				:is-act="actAddress.id == item.id"
				:key="item.id"
				:user-name="item.takeName"
				:phone="item.iphone"
				:address="item.address"
				@editBtnClick="goToEdit(item)"
				@click="check(item)"
			></address-item>
		</view>

		<view class="foot"><button class="btn btn-yellow add-btn" @click="goToEdit(null)">新增收货地址</button></view>
	</container>
</template>

<script>
import addressItem from '@/components/address-item/address-item.vue';

export default {
	components: {
		addressItem
	},
	data() {
		return {
			title: '', //标题
			type: '', //页面类型  我的：'mine' 选择收货地址：'select'
			actAddress:{//当前选中地址
				// addresAlias: null
				// addresType: 0
				// address: "榄树排东街12巷3号"
				// city: "广州市"
				// county: "黄埔区"
				// createBy: ""
				// createTime: "2021-01-11 03:40:27"
				// fixIphone: null
				// id: 20
				// iphone: "18202074132"
				// isDefault: 1
				// params: Object
				// province: "广东省"
				// remark: null
				// searchValue: null
				// takeName: "饶东俊"
				// updateBy: ""
				// updateTime: "2021-01-11 03:40:59"
				// userId: 3
			},
	
			// addressList: [
				// 地址列表
				// {
				// 	id
				// 	addresAlias
				// 	addresType
				// 	address
				// 	city
				// 	county
				// 	createBy
				// 	createTime
				// 	fixIphone	
				// 	iphone
				// 	isDefault
				// 	params
				// 	province	
				// 	remark
				// 	searchValue
				// 	takeName
				// 	updateBy
				// 	updateTime
				// 	userId
						
				// },
				
			// ]
		};
	},
	computed:{
		isNoData(){
			return this.addressList<1
		},
		addressList(){
			// [
			// {
			// 	id
			// 	addresAlias
			// 	addresType
			// 	address
			// 	city
			// 	county
			// 	createBy
			// 	createTime
			// 	fixIphone	
			// 	iphone
			// 	isDefault
			// 	params
			// 	province	
			// 	remark
			// 	searchValue
			// 	takeName
			// 	updateBy
			// 	updateTime
			// 	userId		
			// },
			// ]
			return this.$store.state.addressModule.addressList
		}
	},
	methods: {
		
		check(item) {
			// 编辑按钮点击
			if (this.type == 'select') {
				this.actAddress = item;
				this.$store.commit("setActAddress",this.actAddress)
				this.$store.commit("setTakeAddress",this.actAddress)
				uni.navigateBack({
					delta:1
				})
				console.log('编辑按钮点击');
			}
		},
		goToEdit(item) {
			// 去编辑
			if (item) {
				console.log('去编辑', item);
				var id=item.id
				uni.navigateTo({
					url: `/pages/address/address-edit?id=${id}`
				});
				
			}
			else{
				uni.navigateTo({
					url: `/pages/address/address-edit`
				});
			}
		}
	},
	onLoad(option) {
		console.log('option', option);
		this.title = option.title;
		this.type = option.type;
		uni.setNavigationBarTitle({
			title: option.title
		});
	}
};
</script>

<style lang="scss" scoped>
.address {
	.address-list {
		display: flex;
		flex-direction: column;
		width: 100%;
		box-sizing: border-box;
		padding: 20rpx 20rpx 106rpx 20rpx;
	}

	.item:nth-last-child(n + 2) {
		margin-bottom: 20rpx;
	}
	.foot {
		width: 100%;
		box-sizing: border-box;
		padding: 8rpx 20rpx;
		position: fixed;
		bottom: 0;
		background-color: #f3f5fb;
		.add-btn {
			width: 100%;
			padding: 14rpx 0rpx;
			font-size: 34rpx;
		}
	}
}
</style>
